package com.xls.commonlibrary.http;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

public class SetUtil {


    //list为null会报错
    public static Set<String> listToSet(@Nonnull List<String> list) {
//        List<String> list = new ArrayList<>();
//        list.add("value1");
//        list.add("value2");
//        list.add("value3");

        // fixme：顺序错误
        // Set<String> set = new HashSet<>(list);

        // 保证顺序
        LinkedHashSet<String> set = new LinkedHashSet<>(list);
        System.out.println(set.toString());

        return set;
    }

    //set为null会报错
    public static List<String> setToList(@Nonnull Set<String> set) {
//        Set<String> set = new HashSet<>();
//        set.add("value1");
//        set.add("value2");
//        set.add("value3");
//        set=null;
        List<String> list = new ArrayList<>(set);
        System.out.println(list.toString());
        return list;
    }

}
